﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Ini;

namespace TwipPlays
{
    public partial class Voting : Form
    {
        public Voting()
        {

            InitializeComponent();

            // Initialize values
            IniFile ini = new IniFile("irc_parser/config.ini");

            // Get settings & assign to entries
            bool votingEnabled = (ini.IniReadValue("voting", "votingEnabled") == "true");
            string votingLeftTerm = ini.IniReadValue("voting", "votingLeftTerm");
            string votingRightTerm = ini.IniReadValue("voting", "votingRightTerm");


            string votingBoundsStr = ini.IniReadValue("voting", "votingBounds");
            string actionVoteThresholdStr = ini.IniReadValue("voting", "actionVoteThreshold");

            int votingBounds, actionVoteThreshold;
            int.TryParse(votingBoundsStr, out votingBounds);
            int.TryParse(actionVoteThresholdStr, out actionVoteThreshold);

            this.mode_voting_check.Checked = votingEnabled;
            this.left_term_entry.Text = votingLeftTerm;
            this.right_term_entry.Text = votingRightTerm;
            this.voting_bounds_spin.Value = votingBounds;
            this.action_threshold_spin.Value = actionVoteThreshold;
        }

        private void save_clicked(object sender, EventArgs e)
        {

            // Save values
            IniFile ini = new IniFile("irc_parser/config.ini");

            ini.IniWriteValue("voting", "votingEnabled", (this.mode_voting_check.Checked ? "true" : "false"));
            ini.IniWriteValue("voting", "votingLeftTerm", this.left_term_entry.Text);
            ini.IniWriteValue("voting", "votingRightTerm", this.right_term_entry.Text);
            ini.IniWriteValue("voting", "votingBounds", this.voting_bounds_spin.Value.ToString());
            ini.IniWriteValue("voting", "actionVoteThreshold", this.action_threshold_spin.Value.ToString());

            this.Close();

        }

        private void cancel_clicked(object sender, EventArgs e)
        {

            this.Close();

        }
    }
}
